package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalIntegralGradeVO;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.atguigu.srb.result.ResponseVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-04-15
 */
@Api(tags = "借款人接口")
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    @Resource
    private BorrowerService borrowerService;

    @ApiOperation("借款人额度审核")
    @PostMapping("/approval")
    public ResponseVo approval(@RequestBody BorrowerApprovalIntegralGradeVO borrowerApprovalIntegralGradeVO){
        borrowerService.approval(borrowerApprovalIntegralGradeVO);
        return ResponseVo.ok().message("审核完成");
    }

    @ApiOperation("获取借款人审批的信息")
    @GetMapping("/{id}")
    public ResponseVo approvalInfo(@PathVariable Long id){
        BorrowerApprovalVO borrowerApprovalVO =borrowerService.approvalInfo(id);
        return  ResponseVo.ok().addData("item",borrowerApprovalVO);
    }
    @ApiOperation("获取借款人列表，分页带条件")
    @GetMapping("/{pageNum}/{pageSize}")
    public ResponseVo borrowerListByPage(@RequestParam(value = "key",required = false) String keyword,
                                             @PathVariable Integer pageNum,
                                             @PathVariable Integer pageSize){
        Page<Borrower> page = new Page<>(pageNum, pageSize);
        borrowerService.borrowerListByPage(page,keyword);
        return ResponseVo.ok().addData("page",page);
    }
}

